import { i18nTool } from "./i18en";

export function navGoogleMap(address) {
	let that = this
	// 应用地址
	let url = ''
	// android 包名
	let pname = ''
	// ios id
	let appid
	
	
	
	if (plus.os.name == 'Android') {

		plus.nativeUI.actionSheet({
			title: i18nTool('googleMap.title'),
			cancel: i18nTool('googleMap.cancel'),
			buttons: [{
				title: i18nTool('googleMap.map')
			}]
		}, function(e) {
			switch (e.index) {
				case 1:
					url = 'google.navigation:q=' + address
					pname = 'com.android.vending'
					break;
			}
			if (url) {
				plus.runtime.openURL(url, function() {
					plus.nativeUI.actionSheet({
						title: i18nTool('googleMap.market'),
						cancel: '取消',
						buttons: [{
							title:  i18nTool('googleMap.market'),
						}]
					}, function({
						index
					}) {
						switch (index) {
							case 1:
								plus.runtime.openURL('market://details?id=' + pname,
									function() {
										plus.nativeUI.alert( i18nTool('googleMap.msg'));
									})
						}
					})
				});
			}
		});
	} else {
		plus.nativeUI.actionSheet({
			title: i18nTool('googleMap.title'),
			cancel: i18nTool('googleMap.cancel'),
			buttons: [{
				title: i18nTool('googleMap.map')
			}]
		}, function(e) {
			switch (e.index) {
				case 1:
					url = 'comgooglemaps://?saddr=&daddr=' + address
					appid = 585027354
					break;
				default:
					break;
			}
			if (url != '') {
				plus.runtime.launchApplication({
					action: url
				}, function(err) {
					plus.nativeUI.actionSheet({
						title: i18nTool('googleMap.market'),
						cancel: i18nTool('googleMap.cancel'),
						buttons: [{
							title:i18nTool('googleMap.market')
						}]
					}, function({
						index
					}) {
						switch (index) {
							case 1:
								plus.runtime.openURL(
									`itms-apps://itunes.apple.com/cn/app/id${appid}?mt=8')`,
									function() {
										plus.nativeUI.alert(i18nTool('googleMap.msg'));
									})
						}
					})
				});
			}
		});
	}
}